﻿using Minecraft.Config;
using Minecraft.ConnTest.Send;
using Minecraft.Model;
using Minecraft.Model.ReqResp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Minecraft.ConnTest.Receive
{
	/// <summary>
	/// 连接成功后
	/// </summary>
	public class Conn_Success
	{
		public void Execute(Socket socketClient, EnumCommand command, string respStr)
		{
			var resp = respStr.JsonDeserialize<BaseResp>();
			RespLevelJudge.Do(command, resp, () =>
			{
				//连接成功
				//心跳包
				ThreadPool.QueueUserWorkItem(o =>
				{
					while (true)
					{
						Thread.Sleep(5000);
						ComManager.Send(socketClient, () =>
						{
							return SendHeartData.GetReq();
						});
					}
				});

				//登录
				ComManager.Send(socketClient, () =>
				{
					return SendPlyerLogin.GetReq();
				});
			});
		}
	}
}
